/**
 * 
 */
package co.fitstart.entity.principal;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Transient;
import org.apache.commons.lang3.StringUtils;
import co.fitstart.entity.reference.Gender;

/**
 * @author mohanlan
 */
public class Profile {
    
    /** 头像 */
    private String avatar;
    
    /** 真实姓名 */
    private String realname;
    
    /** 昵称 */
    private String nickname;
    
    /** 性别 */
    @Enumerated(EnumType.ORDINAL)
    private Gender gender;
    
    /** 擅长 */
    private String specialty;
    
    /** 个人简介 */
    private String description;
    
    /** 特色课标签 */
    private String specialTags;
    
    /**
     * The default constructor
     */
    public Profile() {
        
    }
    
    /**
     * 
     * @param avatar
     * @param nickname
     * @param gender
     */
    public Profile(String avatar, String nickname, Integer gender) {
        
        // we do not update avatar
        
        this.nickname = nickname;
        this.gender = Gender.codeOf(gender);
    }
    
    public Profile editSpecilTags(List<SpecialTags> tags) {
        if(org.apache.commons.collections.CollectionUtils.isNotEmpty(tags)) {
            String code = "";
            for(SpecialTags tag : tags) {
                code = code + tag.getCode();
            }
            
            this.specialTags = code;
        } else {
            this.specialTags = null;
        }
        return this;
    }
    
    public List<SpecialTags> getTags() {
        List<SpecialTags> result = new ArrayList<SpecialTags>();
        if(this.specialTags != null) {
            for (SpecialTags specialTag : SpecialTags.values()) {
                if(this.specialTags.contains(specialTag.getCode())) {
                    result.add(specialTag);
                }
            }
        }
        
        return result;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String[] getSpecialtyArray() {
        return StringUtils.split(this.specialty, ",");
    }
    
    /**
     * @return the avatar
     */
    public String getAvatar() {
        return avatar;
    }

    /**
     * @return the realname
     */
    public String getRealname() {
        return realname;
    }

    /**
     * @return the nickname
     */
    public String getNickname() {
        return nickname;
    }

    /**
     * @return the gender
     */
    public Gender getGender() {
        return this.gender;
    }
    
    /**
     * @return
     */
    public String getSpecialty() {
        return specialty;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param avatar the avatar to set
     */
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    /**
     * @param realname the realname to set
     */
    public void setRealname(String realname) {
        this.realname = realname;
    }

    /**
     * @param nickname the nickname to set
     */
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(Gender gender) {
        this.gender = gender;
    }
    
    /**
     * @param specialty
     */
    public void setSpecialty(String specialty) {
        this.specialty = specialty;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }
    
    public String getSpecialTags() {
        return specialTags;
    }
    
    public void setSpecialTags(String specialTags) {
        this.specialTags = specialTags;
    }
}
